<?php
require_once 'prepend.php';

require_once 'PHPTAL.php';
require_once 'MTranslator.php';

$skin = 'default';
#$skin = 'bitter_sweet';

// execute the template
try {
	$tr = new MTranslator();
	// set language to use for this session (first valid language will
	// be used)
	if(!$_GET['lang'] || $_GET['lang'] == 'en')
		$tr->setLanguage('en', 'en_GB.utf8', 'en_GB');
	else
		$tr->setLanguage('pt_BR.utf8');
	
	// create a new template object
	#$tpl = new PHPTAL($_SERVER['DOCUMENT_ROOT'].MConfig::$obCfg->path->skins_path.'/default/default.tpl');
	$tpl = new PHPTAL($_SERVER['DOCUMENT_ROOT'].MConfig::$obCfg->path->skins_path.'/'.$skin.'/msearch.tpl');
	
	// tell PHPTAL to use our translator
    $tpl->setTranslator($tr);
    
    /*.................. SET VARS*/
    $mmenu = MConfig::getMMenu();
    //var_dump($mmenu);
	//foreach($mmenu as $k => $v){echo "<br>$k => $v<br>";}
    $tpl->menuOptions = $mmenu;
    $tpl->lang = !$_GET['lang'] ? 'en' : $_GET['lang'];
    $tpl->action = !array_key_exists('action',$_GET) ? false : $_GET['action'];
    
    switch ($_GET['action']) {
    	case 'list':
    		$tpl->edit_list = false;
    		$tpl->content = $tr->getList(1);
    		
	    	if($_GET['edit']):
	    		$tpl->edit = $_GET['edit'];
	    		$tpl->edit_list = 'Edit item [' . $_GET['edit'] . ']';
	    		$tpl->content =  false;	
	    		$tpl->update = false;
	    		$tpl->editRes = $tr->editListResult($_GET['edit']);
	    	elseif($_GET['delet']):
	    		$tpl->content =  'Romve ' . $_GET['delet'];
	    	endif;
	    	
	   		if(array_key_exists('update', $_GET)){
	   			//echo "am i here in update?<br>";
	   			$tpl->update = true;
	   			$tpl->content = false;
	   			$tpl->editRes = $tr->editListResult($_GET['edit'], $_GET['edit_list']);
	   		}
    	break;
    	
    	case 'add_lang':
    	$tpl->content = null;
    	
    	case 'add_domain':
    	$tpl->content = null;
    	break;
    }
    
    
    /*.................. END VARS*/

	echo $tpl->execute();
}
catch (Exception $e){
	echo $e;
}


?>